<?php  

require '../../frame/base.php';

$tag = !empty($_REQUEST['tag'])?$_REQUEST['tag']:null;
$uid = !empty($_REQUEST['uid'])?$_REQUEST['uid']:null;
$ordersid = !empty($_REQUEST['ordersid'])?$_REQUEST['ordersid']:null;


if($tag=='oldorders'){

// 分页
if($_REQUEST['page']!="" && $_REQUEST['pagesize']!=""){
	$de=$_REQUEST['page']*$_REQUEST['pagesize'];
	$size=$_REQUEST['pagesize'];
}else{
	$de=0;
	$size=20;
}
// 分页 end

	$w=['c.userid'=>$uid,'c.state'=>'5'];
	$joins=array(['shop s','c.shopid=s.shopid','LEFT']);
	$return=$Db->table('car')->alias('c')->join($joins)->field('s.name,s.head_pic,c.ordersid,c.goodsname,c.fTitle,c.sTitle,c.price,c.caizhi,c.chicun,c.created_at')->where($w)->limit($de,$size)->select();
	$ary=$return;

}elseif($tag=='neworders'){
	$w=['userid'=>$uid,'ordersid'=>$ordersid,'state'=>'5'];
	$colms='total_numbers,numbers,totalprice,userid,address,kuaidi,shopid,youhui,freightRisk_price,buyFreightRisk,distribution_fee,type,coupon_id,coupon_price,pay_type,is_nobody,fan_yong_price,fan_juan_price,return_volume_price,invoice_type,invoice_data,fan_juan_bi_li,fan_yong_bi_li';
	$w1=['carid','created_at','state'];
	$arr1 = $Db->table('goodsorders')->field($colms)->where($w)->find();
	$totalprice=$arr1['totalprice'];
	$returnId=$Db->table('goodsorders')->where($w)->insertGetId($arr1);
	$arr2 = $Db->table('car')->field($w1,true)->where($w)->find();
	$carId=$Db->table('car')->where($w)->insertGetId($arr2);
	$ary=array('totalprice'=>$totalprice,'newId'=>$returnId);	
}else{
	$ary=[];
}
echo json_encode(['code'=>200,'msg'=>'成功','data'=>$ary]);